package com.itcoon.cloud.framework.transform.assemble.validator;


import com.itcoon.cloud.framework.transform.exception.AssembleException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Miaoxia Yu
 * @date 2020-11-05
 */
public class SourceValidatorComposite {

    @Autowired
    private List<SourceValidator> sourceValidators;

    public void validate(Object source, Class<?> originClass){
        if(!originClass.isAssignableFrom(source.getClass())){
            throw new AssembleException(String.format("[Transform4j] - Error Source Type, required source is {}, but not found", originClass.getName()));
        }
//        SourceValidator lastValidator = sourceValidators.get(sourceValidators.size()-1);
//        if(!(lastValidator instanceof StandardSourceValidator)){
//            throw new AssembleException("Incorrect order for source validator,the order of standard validator must be max in validators");
//        }
//        for (SourceValidator sourceValidator : sourceValidators) {
//            if(sourceValidator.support(source)){
//                sourceValidator.validate(source, originClass);
//                return;
//            }
//        }

    }

}
